package com.mine.async.enums;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;

public enum JobTypeEnum {

    TEST("test", "测试文件", "测试", 5000, 20000);
    private String code;

    private String name;

    private String sheetName;

    private boolean autoSheet;

    private int sheetLimit;

    private int selectLimit;

    JobTypeEnum(String code, String name, String sheetName) {
        this.code = code;
        this.name = name;
        this.sheetName = sheetName;
        this.autoSheet = false;
        this.selectLimit = 1000;
    }

    JobTypeEnum(String code, String name, String sheetName, int selectLimit) {
        this.code = code;
        this.name = name;
        this.sheetName = sheetName;
        this.autoSheet = false;
        this.selectLimit = selectLimit;
    }

    JobTypeEnum(String code, String name, String sheetName, int selectLimit, int sheetLimit) {
        this.code = code;
        this.name = name;
        this.sheetName = sheetName;
        this.autoSheet = true;
        this.selectLimit = selectLimit;
        this.sheetLimit = sheetLimit;
    }


    public String getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public boolean isAutoSheet() {
        return autoSheet;
    }

    public int getSheetLimit() {
        return sheetLimit;
    }

    public int getSelectLimit() {
        return selectLimit;
    }

    public String getSheetName() {
        return sheetName;
    }

    public static String getNameByCode(String code) {
        if (StrUtil.isEmpty(code))
            return "";
        for (JobTypeEnum typeEnum : JobTypeEnum.values()) {
            if (ObjectUtil.equals(code, typeEnum.code))
                return typeEnum.name;
        }
        return "";
    }

    public static JobTypeEnum getByCode(String code) {
        if (StrUtil.isEmpty(code))
            return null;
        for (JobTypeEnum typeEnum : JobTypeEnum.values()) {
            if (ObjectUtil.equals(code, typeEnum.code))
                return typeEnum;
        }
        return null;
    }
}
